<?php
interface UHU_Achievement
{
	public function uid();
	public function title();
	public function description();

	public function parents();
	public function children();
	public function siblings();

	public function category();
		public function category_title();

	public function image();
}

require_once('collection.php');

class UHU_Achievements extends UHU_Static_Collection
{
	public static function getReflector()
	{
		static $reflector;
		if(isset($reflector) === false)
		{
			$reflector = new ReflectionClass('UHU_Achievement');
		}
		return $reflector;
	}
	public function __toString()
	{
		$foo = array_keys($this->data);
		if(empty($foo))
		{
			return '';
		}
		else
		{
			sort($foo);
			return implode(',',$foo);
		}
	}
}

interface UHU_Achievement_gen
{
	public function last_action();

	public static function get_all();

	public static function get_parents(UHU_Achievement_gen $Achievement);
	public static function get_children(UHU_Achievement_gen $Achievement);
	public static function get_siblings(UHU_Achievement_gen $Achievement);

	public static function get_category(UHU_Achievement_gen $Achievement);

	public static function has_children(UHU_Achievement_gen $Achievement);
	public static function has_parents(UHU_Achievement_gen $Achievement);
	public static function has_siblings(UHU_Achievement_gen $Achievement);

	public static function last_db_update();
}


interface UHU_Achievement_Category
{
	public function title();
	public function description();
	public function image();
#	public static function images($uid);
}

class UHU_Achievement_Categories extends UHU_Static_Collection
{
	public static function getReflector()
	{
		static $reflector;
		if(isset($reflector) === false)
		{
			$reflector = new ReflectionClass('UHU_Achievement_Category');
		}
		return $reflector;
	}
}

abstract class UHU_Achievement_Category_generated implements UHU_Achievement_Category
{
	protected $title;
	protected $description;
	protected $image;
		protected $image_obj;
	public function title()
	{
		return $this->title;
	}
	public function description()
	{
		return $this->description;
	}
	public function image()
	{
		if(isset($this->image_obj) === false)
		{
			$this->image_obj = self::images($this->image);
		}
		return $this->image_obj;
	}
}


interface UHU_Achievement_Image
{
	public function uid();
	public function url();
}

class UHU_Achievement_Images extends UHU_Static_Collection
{
	public static function getReflector()
	{
		static $reflector;
		if(isset($reflector) === false)
		{
			$reflector = new ReflectionClass('UHU_Achievement_Image');
		}
		return $reflector;
	}
}

abstract class UHU_Achievement_Image_PDO implements UHU_Achievement_Image
{
	public function uid()
	{
		return $this->uid;
	}
	public static function get($uid)
	{
		static $images;
		if(isset($images) === false)
		{
			$images = new UHU_Achievement_Images;
			$sth = null;
			UHU_PDO_helper::prepare(UHU_Install_PDO::readonly(),self::sql_get,$sth);
			UHU_PDO_helper::exec($sth);
			foreach(UHU_PDO_helper::fetchAll_Class($sth,get_class(new self)) as $image)
			{
				$images[$image->uid()] = $image;
			}
		}
		if(isset($images[$uid]) === false)
		{
			throw new RuntimeException('Could not find an image with that UID.');
		}
		else
		{
			return $images[$uid];
		}
	}
	public function url()
	{
		return $this->url;
	}
}


?>